
/*
file:matrix.h
author:Hui Hern
time:Thu 20:47
date:7 Oct 2021
brief:Multiplication of matrices(more to be done)T^T
*/

#include<iostream>
using namespace std;

template<typename T>
class Matrix
{
 public:
      int n;
      int n_row,n_col;
      T** matrix_elements = NULL;
  
 public:
    bool Is_square() //To identify whether the matrix is square or not.If it is, the value of the bool is 1,or else 0
      {
        if(n_row == n_col)return true;
        else return false;
      }

    Matrix(T row,T col)//Constructor
    {
        n_row = row;//n_row is in an usage of class while row is the input from user
        n_col = col;//n_col is in an usage of class while col is the input from user

        matrix_elements = new T*[row];
        for (int i = 0;i < n_row;i++)
        {
            matrix_elements[i] = new T[n_col];
        }
    }

    /*    ~Matrix()//Deconstructor:It might have some mistakes
    {
      for (int i = 0;i < n_row;i++)
      {
           delete[] matrix_elements[i];
      }
      delete[] matrix_elements;
      }*/

    void print_matrix()
    {
        for (int i = 0;i < n_row;i++)
         {
            for (int j = 0;j < n_col;j++)
            {
                cout << matrix_elements[i][j] <<'\t';
            }
            cout << endl;
         }
    }
    Matrix operator*(const Matrix& m){//Overload an operator *
        Matrix temp(n_row,m.n_col);
        for(int i=0;i<n_row;i++){
            for(int j=0;j<n_col;j++){
                for(int k=0;k<n_row;k++){
                    temp.matrix_elements[i][j]+=matrix_elements[i][k]*m.matrix_elements[k][j];
                }
            }
        }
        return temp;
    }
};

template<typename T>//Derived Class
class RowVector:public Matrix<T>
{
private: int row,col;
public:
    Matrix<T> M1;
    T* rowvector =NULL;
    RowVector(int row){
        for (int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                rowvector[i]=M1.matrix_elements[i][j];
            }
        }
    }
    void print_RowVector(){
        for(int i=0;i<row;i++){
            cout<<rowvector[i];
        }
    }
};

template<typename T>//Derived Class
class ColVector:public Matrix<T>
{
private: int row,col;
public:
    Matrix<T> M1;
    T* colvector =NULL;
    ColVector(int col){
        for (int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                colvector[j]=M1.matrix_elements[i][j];
            }
        }
    }
    void print_ColVector(){
        for(int j=0;j<col;j++){
            cout<<colvector[j];
        }
    }
};

